<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <style>
        thead tr th {
            text-align: center !important;
            font-weight: bold !important;
        }

        tr td {
            text-align: center !important;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card-header">
                <div class="layui-col-md-offset11">
                    <button class="layui-btn layui-btn-sm layui-btn-normal" onclick="history.go(-1)">返回上一页</button>
                </div>
            </div>
            <div class="layui-card">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                    <div class="layui-form-item">
                        <div class="test-table-reload-btn layui-col-sm-offset3">
                            <div class="layui-col-md12">
                                <div class="layui-col-md4">
                                    <div class="layui-col-sm3" style="line-height: 38px">注册时间：</div>
                                    <div class="layui-col-sm7">
                                        <input class="layui-input" name="queryTime" id="laydate-cn" autocomplete="off">
                                    </div>
                                </div>
                                <div class="layui-col-md4">
                                    <div class="layui-col-sm3" style="line-height: 38px">用户昵称：</div>
                                    <div class="layui-col-sm7">
                                        <input type="text" name="nickName" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-col-md4">
                                    <div class="layui-col-sm3" style="line-height: 38px">用户账号：</div>
                                    <div class="layui-col-sm7">
                                        <input type="text" name="phone" class="layui-input">
                                    </div>
                                </div>

                            </div>
                            <div class="layui-col-xs12">&nbsp;</div>
                            <div class="layui-col-md12">
                                <div class="layui-col-md4">
                                    <div class="layui-col-sm3" style="line-height: 38px">真实姓名：</div>
                                    <div class="layui-col-sm7">
                                        <input type="text" name="realName" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-col-sm4">
                                    <button class="layui-btn layuiadmin-btn-list" lay-submit
                                            lay-filter="LAY-app-contlist-search">
                                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查询
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-card-body">
                    <input type="hidden" name="content" value="${content}">
                    <table class="layui-table" lay-filter="customer-table" id="customer-table"></table>
                    <div class="layui-form-item" style="text-align:center">
                        <div class="layui-footer" style="left: 0;">
                            <button type="button" class="layui-btn" data-type="getCheckData">
                                <i class="layui-icon">&#xe681</i>推送站内信
                            </button>
                        </div>
                    </div>
                    <script type="text/html" id="index">
                        {{d.LAY_TABLE_INDEX+1}}
                    </script>
                    <script type="text/html" id="status">
                        {{#  if(d.status == 1){ }}
                        <span class="layui-badge layui-bg-green">正常</span>
                        {{# }else{ }}
                        <span class="layui-badge">冻结</span>
                        {{# }}}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'table', 'laydate'], function () {
        var form = layui.form, table = layui.table, $ = layui.$, laydate = layui.laydate;

        laydate.render({
            elem: '#laydate-cn',
            range: '~'
        });

        table.render({
            elem: '#customer-table',
            url: '/customer/queryCustomerList',
            page: true,
            request: {
                pageName: 'current',
                limitName: 'size'
            },
            cols: [[
                {type: 'checkbox'},
                {field: 'id', title: '序号', width: 80, templet: '#index'},
                {field: 'nickName', title: '昵称', minWidth: 150},
                {field: 'phone', title: '账号', minWidth: 120},
                {field: 'channelName', title: '用户来源', minWidth: 100},
                {field: 'realName', title: '真实姓名', minWidth: 100},
                {field: 'remarkname', title: '平台备注', minWidth: 100},
                {field: 'status', title: '状态', minWidth: 80, templet: '#status'},
                {
                    field: 'createtime', title: '注册时间', minWidth: 170, sort: true,
                    templet: "<div>{{layui.util.toDateString(d.createtime,'yyyy-MM-dd HH:mm:ss')}}</div>"
                }
            ]]
        });

        form.on('submit(LAY-app-contlist-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('customer-table', {
                where: field
            });
        });

        //监听表格复选框选择
        table.on('checkbox(customer-table)', function (obj) {
            var checkStatus = table.checkStatus('customer-table'), data = checkStatus.data;
            if (data.length > 20) {
                layer.alert("最多选择20个");
            }
        });

        var $ = layui.$, active = {
            getCheckData: function () { //获取选中数据
                var checkStatus = table.checkStatus('customer-table'), data = checkStatus.data;
                var content = $("input[name='content']").val();
                var emptyList = [];     //选中的数组
                for (var i = 0; i < data.length; i++) {
                    emptyList.push(data[i].id);
                }
                $.ajax({
                    type: 'post',
                    url: "/news/handlePush",
                    data: {"content":content,"pushType":"single","cidlist":emptyList},
                    dataType: 'json',
                    traditional:true,
                    success: function (data) {
                        if (data.status) {
                            layer.msg(data.desc);
                            setTimeout(function () {
                                window.location.reload();
                            }, 1000)
                        } else {
                            layer.msg(data.desc);
                        }
                    },
                    error: function () {
                        layer.msg("请检查页面信息是否正确");
                    }
                });
            }
        };

        $('.layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>
</body>
</html>